package com.framework.config;

import javax.servlet.Filter;
import javax.servlet.ServletRegistration;

import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

/**
 * WebApplicationInitializer 를 상속하면, 서블릿 컨테이너가 실행될 때 onStartup() 메소드가 자동으로 호출된다.
 * 이 클래스는 web.xml 의 역할을 대신하거나 보충한다.
 */
public class WebXmlConfiguration extends AbstractAnnotationConfigDispatcherServletInitializer {

	@Override
	protected Class<?>[] getRootConfigClasses() {
		return new Class<?>[] {
				RootConfig.class
				, MybatisConfig.class
				, ViewTemplateConfig.class
				};
	}

	@Override
	protected Class<?>[] getServletConfigClasses() {
		return new Class<?>[] {
				WebMvcConfig.class
			};
	}

	@Override
	protected String[] getServletMappings() {
		return new String[] { "/" };
	}

	@Override
    protected boolean isAsyncSupported() {
        return true;
    }

    @Override
    protected Filter[] getServletFilters() {
        CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter();
        encodingFilter.setEncoding("UTF-8");
        encodingFilter.setForceEncoding(true);
        return new Filter[] { encodingFilter };
    }

    @Override
    protected void customizeRegistration(ServletRegistration.Dynamic registration) {
    	registration.setInitParameter("spring.profiles.default", "default");
    	registration.setInitParameter("spring.profiles.active", "default");
    	registration.setInitParameter("dispatchOptionsRequest", "true");
    }
}
